/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */

package cn.webrx;

import java.io.FileInputStream;
import java.io.FileReader;

/**
 * <p>Project: jse2303 - File4
 * <p>Powered by webrx On 2023-07-20 17:19:47
 * <p>描述：<p>
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class File4 {
    public static void main(String[] args) {
        //读取文件 记事本文件
        String f = "user.txt";
        f = "D:\\0703\\javase\\jse2303\\jse2303\\ch09\\src\\cn\\webrx\\File1.java";
        //字节流
        try (var is = new FileInputStream(f)) {
            String txt = new String(is.readAllBytes());
            System.out.println(txt);
            //System.out.println(txt.lines().count());
        } catch (Exception e) {

        }
        //字符流
        try (FileReader reader = new FileReader(f)) {
            StringBuilder sbu = new StringBuilder();
            while (reader.ready()) {
                sbu.append(String.format("%c", reader.read()));
                //System.out.print((char) reader.read());
            }
            //System.out.println(sbu);
            System.out.println(sbu.toString().lines().count());
        } catch (Exception e) {

        }


    }
}
